package services;

import javax.ejb.Stateless;

//import org.slf4j.*;
import org.apache.commons.lang.StringUtils;

import services.solDistWS.SolDistWSProxy;

import java.rmi.RemoteException;

import entitybeans.CentroDistribucion;

@Stateless
public class SOAPAdministratorBean implements SOAPAdministrator {

	@Override
	public void enviarSolDist(String text, CentroDistribucion cd) {
		System.out.println("SOAPAdministratorBean.enviarSolDist() \nXML: " + text);
		
		try {
			
//			System.out.println("\n\n ENTRE AL TRY!!!! DE SOAPAdministratorBean\n\n");
			
			SolDistWSProxy proxy = new SolDistWSProxy();
			
			if (StringUtils.isNotEmpty(cd.getEndpoint())) {
				proxy.setEndpoint(cd.getEndpoint());
			}
			
//			System.out.println("\n\n PASE EL NEW SOLDIST \n\n");
			
			boolean result = proxy.recibirSolDist(text);
			
			if (result) {
				System.out.println("SOLDIS ENVIADA CORRECTAMENTE A CD [" + cd.getNombre() + "] - ENDPOINT: " + proxy.getEndpoint());
			} else {
				System.out.println("ERROR AL ENVIAR SOLDIS A CD [" + cd.getNombre() + "] - ENDPOINT: " + proxy.getEndpoint());
			}

		} 
		catch (RemoteException e) {
			System.out.println("EXPLOTO ALGO EN EL SOAPAdministratorBean");
		}
	}

}